package com.lemei.cn.adpter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.lemei.cn.lemeiapp.R;

import java.util.List;

/**
 * Created by 赵航 on 2017/6/4.
 */

public class MyRecycleViewAdpter extends RecyclerView.Adapter {

    private List<Integer> mImageViews;

    public MyRecycleViewAdpter(List<Integer> list) {
        mImageViews = list;
    }


    //对应的viewhodler
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.chanpin, null);


        return new Holder(view);
    }

    //赋值，更新数据
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        Holder adpter = (Holder) holder;
        adpter.mImageView.setImageResource(mImageViews.get(position));
        adpter.mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnPagerClikeListen!=null){
                    mOnPagerClikeListen.onPageClike(position);
                }
            }
        });
    }
    //列表的条目数
    @Override
    public int getItemCount() {
        return mImageViews.size();
    }

    public interface OnPagerClikeListen{
        void onPageClike(int postion);
    }

    private OnPagerClikeListen mOnPagerClikeListen;

    public void setOnPagerClikeListen(OnPagerClikeListen onPagerClikeListen){
        this.mOnPagerClikeListen = onPagerClikeListen;
    }
}
